#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define flr(x,l,r) for (int x = l; x <= r; ++ x)
#define frl(x,r,l) for (int x = r; x >= l; -- x)
#define LL long long 
#define szf sizeof
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define inll(x) scanf("%lld", &x)
#define outll(x) printf("%lld", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector 
#define pb push_back
#define sz size
#define PII pair<int, int>

using namespace std;

const int N = 1e5 + 10;

int n, m;
LL s[N], f[N];
int q[N];

LL g(int i) {
    if (!i) return 0ll;
    return f[i - 1] - s[i];
}

int main() {
	in(n), in(m);
	
	flr (i, 1, n) inll(s[i]), s[i] += s[i - 1];
	
	int hh = 0, tt = 0;
	flr (i, 1, n) {
	    if (q[hh] < i - m) hh ++ ;
	    f[i] = max(f[i - 1], g(q[hh]) + s[i]);
	    while (hh <= tt && g(q[tt]) <= g(i)) tt -- ;
	    q[ ++ tt] = i;
	}
	
	outll(f[n]), pn;
	
	return 0;
}